package cn.sixos.entity;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.forten.utils.system.CurrentTimeKeyBuilder;

@Entity
@Table(name = "TEST_USER")
public class User implements Serializable {
	private static final long serialVersionUID = 1181828989028121552L;
	@Id
	private long id;
	@Column
	private String userName;
	@Column
	private String password;
	@Column
	private String userEmail;
	@Column
	private String sex;
	@Column
	private String dept;
	@Column
	private String role;
	@Column
	private int state;
	@ManyToMany
	@JoinTable(name = "TEST_USER_COURSE", joinColumns = { @JoinColumn(name = "USER_ID") }, inverseJoinColumns = { @JoinColumn(name = "COURSE_ID") })
	private Set<Course> courseSet;

	public User() {
		super();
		this.id=CurrentTimeKeyBuilder.getInstance().nextPK();
		this.state=2;
		this.courseSet= new HashSet<Course>();
	}

	public User(String userName, String password, String userEmail, String sex,
			String dept, String role) {
		this();
		this.userName = userName;
		this.password = password;
		this.userEmail = userEmail;
		this.sex = sex;
		this.dept = dept;
		this.role = role;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getUserEmail() {
		return userEmail;
	}

	public void setUserEmail(String userEmail) {
		this.userEmail = userEmail;
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public String getDept() {
		return dept;
	}

	public void setDept(String dept) {
		this.dept = dept;
	}

	public String getRole() {
		return role;
	}

	public void setRole(String role) {
		this.role = role;
	}

	public int getState() {
		return state;
	}

	public void setState(int state) {
		this.state = state;
	}

	public Set<Course> getCourseSet() {
		return courseSet;
	}

	public void setCourseSet(Set<Course> courseSet) {
		this.courseSet = courseSet;
	}

	public long getId() {
		return id;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (int) (id ^ (id >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		User other = (User) obj;
		if (id != other.id)
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "User [id=" + id + ", userName=" + userName + ", password="
				+ password + ", userEmail=" + userEmail + ", sex=" + sex
				+ ", dept=" + dept + ", role=" + role + ", state=" + state
				+ ", courseSet=" + courseSet + "]";
	}

}
